package com.kwin.test.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

/**
 * @author : Kwin
 * @version V1.0
 * @Package com.kwin.test.config
 * @Description:
 * @date 2021年06月11日 10:33
 **/

@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
public class MybatisPlusConfig {
    
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        return mybatisPlusInterceptor;
    }
    @Bean
    public PaginationInnerInterceptor paginationInterceptor(MybatisPlusInterceptor mybatisPlusInterceptor) {
        // 分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        
        // 请求页面大于最大页后操作，true调回首页，false继续请求 默认false
        paginationInnerInterceptor.setOverflow(false);
        // 单页最大数量限制，默认500， -1不限制
        paginationInnerInterceptor.setMaxLimit(500L);
        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
        
        return paginationInnerInterceptor;
    }
    
    @Bean
    public MetaObjectHandler metaObjectHandler() { return new CustomMetaObjectHandler(); }
}